package com.zy.cat.entity.resp;

import java.io.Serializable;
import java.util.List;

import com.github.pagehelper.Page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author Link
 * @date 2019-03-06 11:44
 * @param <T>
 */
@Data
@AllArgsConstructor
@ApiModel(value="带分页信息的数据返回实体类",description="用于带分页的请求接口")
public class ResultPage<T> implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 10315986L;
 
	@ApiModelProperty(value = "当前页，默认", example = "1")
	private int pageNum;
 
	@ApiModelProperty(value = "当前页每页数量", example = "10")
	private int pageSize;
 
	@ApiModelProperty(value = "查询结果总条数", example = "10")
	private long total;
 
	@ApiModelProperty(value = "查询结果总页数", example = "10")
	private int pages;
	
	@ApiModelProperty(value = "查询结果数据", example = "[{}]")
	private List<T> list;
	
	
	public ResultPage() {
		super();
	}
	
 
	
	public ResultPage(Page<T> page) {
		super();
		this.pageNum = page.getPageNum();
		this.pageSize = page.getPageSize();
		this.total = page.getTotal();
		this.pages = page.getPages();
		this.list=page;
	}
	
	/**
	 * 请求数据时配置请求的页数
	 */
	public ResultPage(int pageNum, int pageSize) {
		super();
		this.pageNum = pageNum;
		this.pageSize = pageSize;
	}
	
	public ResultPage(int pageNum, int pageSize,int total,List<T> data) {
		super();
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.total = total;
		this.list=data;
		if(total%this.pageSize==0) {
			this.pages =total/this.pageSize;
		}else {
			this.pages =total/this.pageSize+1;
		}
	}
	
	public ResultPage(int pageNum) {
		super();
		if(pageNum<=0) {
			pageNum=1;
		}
		this.pageNum = pageNum;
	}
}
